//
//  CZMainTabViewController.swift
//  weiBo
//
//  Created by apple on 16/5/10.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZMainTabViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        //设置tabbar为自定义的tabbar
        let czTabBar = CZTabBar()
        czTabBar.czDelegate = self
        czTabBar.composeButtonClousre = {[weak self] in
//            print("我也哈哈")
//            print(self)
            self!.showComposeVC()
        
        }
        

        
        
        setValue(czTabBar, forKey: "tabBar")       
        addChildViewController(CZHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(CZMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(CZDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(CZProfileViewController(), title: "我的", imageName: "tabbar_profile")
    }

    func addChildViewController(childController: UIViewController,title : String , imageName : String) {
//        childController.tabBarItem.title = title
//        childController.navigationItem.title = title
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(14)], forState: .Normal)
        let nav = UINavigationController(rootViewController: childController)
   
        addChildViewController(nav)
    }
    
    
    //点击加号按钮
    private func showComposeVC() {
        let vc = CZComposeController()
        let nav = UINavigationController(rootViewController: vc)
        self.presentViewController(nav, animated: true, completion: nil)
    }
    
    
}


extension CZMainTabViewController:CZTabBarDelegate{
    func didSelectedComposeButton(){
//        print("我是代理对象")
    }
    
}